package com.stillalive.blogsystem.common.util;

import com.stillalive.blogsystem.pojo.dataobject.BlogInfo;
import com.stillalive.blogsystem.pojo.dataobject.UserInfo;
import com.stillalive.blogsystem.pojo.request.UpdateBlogRequest;
import com.stillalive.blogsystem.pojo.response.BlogInfoResponse;
import com.stillalive.blogsystem.pojo.response.UserInfoResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

@Slf4j
public class BeanTransUtils {
    public static BlogInfoResponse trans(BlogInfo blogInfo){
        if(blogInfo == null){
            return null;
        }
        BlogInfoResponse response = new BlogInfoResponse();
        BeanUtils.copyProperties(blogInfo,response);
        response.setTime(blogInfo.getCreateTime());
        return response;
    }

    public static UserInfoResponse trans(UserInfo userInfo){
        if(userInfo == null){
            return null;
        }
        UserInfoResponse response = new UserInfoResponse();
        BeanUtils.copyProperties(userInfo,response);
        return response;
    }

    public static BlogInfo trans(UpdateBlogRequest updateBlogRequest){
        if(updateBlogRequest == null){
            return null;
        }
        BlogInfo blogInfo = new BlogInfo();
        BeanUtils.copyProperties(updateBlogRequest,blogInfo);
        return blogInfo;
    }
}
